﻿using FH.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Linq;
namespace WebSite.Controllers
{
    [Authorize(AuthenticationSchemes = FHCookieAuthenticationDefaults.AuthenticationScheme)]
    public abstract class FonourControllerBase : Controller
    {
        //public override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    //byte[] result;
        //    //string userid;
        //    //filterContext.HttpContext.Session.TryGetValue("CurrentUser", out result);
        //    if (!filterContext.HttpContext.Session.Keys.Contains("CurrentUserId"))
        //    {
        //        filterContext.Result = new RedirectResult("/Login/Index");
        //        return;
        //    }
        //    //filterContext.HttpContext.Session.Keys.(, out userid);
        //    //if (string.IsNullOrEmpty(userid))
        //    //{
        //    //    filterContext.Result = new RedirectResult("/Login/Index");
        //    //    return;
        //    //}
        //    base.OnActionExecuting(filterContext);
        //}

        /// <summary>
        /// 获取服务端验证的第一条错误信息
        /// </summary>
        /// <returns></returns>
        public string GetModelStateError()
        {
            foreach (var item in ModelState.Values)
            {
                if (item.Errors.Count > 0)
                {
                    return item.Errors[0].ErrorMessage;
                }
            }
            return "";
        }
    }
}
